package cn.leida.local;

import cn.leida.ruoyi.client.service.ICleanSysDataService;
import cn.leida.ruoyi.client.service.ISysClientService;
import cn.leida.ruoyi.framework.jpa.config.LeidaJPAConfig;
import cn.leida.ruoyi.system.service.ISysMenuService;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lei
 * @create 2025-03-12 22:36
 */
@Component
public class LocalClientServer {
    @Autowired
    private ISysMenuService menuService;
    @Autowired
    private LeidaJPAConfig appConfig;
    @Autowired
    private ISysClientService clientService;
    @Autowired
    private ICleanSysDataService sysDataService;


    /**
     * 初始化菜单
     */
    @Transactional(rollbackFor = Exception.class)
    @PostConstruct
    public void initLocalMenu() {
        // 加载菜单
        clientService.loadClientData();
        // 创建超级管理员
        sysDataService.initAdminUser();
    }

    /**
     * 压缩DB文件大小: 彻底清除delete语句执行后的数据
     */
    @Transactional(rollbackFor = Exception.class)
    @PostConstruct
    public void cleanSysData() {
        int deleteDays = 7;
        sysDataService.cleanClientSysData(deleteDays);
    }

}
